package cn.myworld.algorithm.sort;

import cn.myworld.algorithm.common.BaseSort;

/**
 * 冒泡排序
 */
public class Bubble extends BaseSort {

    public static void sort(Comparable[] a) {
        for (int i = a.length - 1; i > 0; i--) {
            for (int j = 0; j < i; j++) {
                // 比较索引j和索引j+1处的值
                if (greater(a[j], a[j + 1])) {
                    exch(a, j, j + 1);
                }
            }
        }
    }

}
